import heapq
from collections import Counter

# 读取输入
T = int(input().strip())
words = [input().strip() for _ in range(T)]
k = int(input().strip())

# 统计词频并构造堆元素
freq = Counter(words)
heap = [(-count, word) for word, count in freq.items()]

# 使用堆获取前k个高频单词
k_largest = heapq.nsmallest(k, heap)

# 提取结果并输出
result = [word for (neg_count, word) in k_largest]
for word in result:
    print(word)
    
"""

16
redundant
code
datotal
inc
dangerous
functions
datotal
cute
standard
dismissed
cyclomatic
complexity
datotal
cute
cute
inc
3
"""